package dao

import (
	"fmt"
	"github.com/google/uuid"
	__ "user-srv/basic/proto"
	"user-srv/handler/models"
)

// 续费添加
func MemberServiceAdd(in *__.MemberServiceAddReq) (*models.MemberService, error) {
	var memberService models.MemberService
	//var memberLevel models.MemberLevel

	memberService.OrderOr = uuid.NewString()                                                 //续费订单
	memberService.UserId = in.UserId                                                         //续费用户
	memberService.Duration = uint32(in.Duration)                                             //续费时长
	memberService.LevelId = in.LevelId                                                       //会员id
	memberService.Amount = float64(in.Duration) * models.MemberServicePrice(int(in.LevelId)) //续费金额

	err := memberService.MemberServiceAdd()
	if err != nil {
		return nil, fmt.Errorf("续费添加失败")
	}

	return &memberService, nil
}
